package com.cc.springboot_test.service;

/**
 * 身份证转换 15位转18位
 */
public class IdNumberTransService {
    public static String conver15to18(String fifteenNumber) {
        try {
            if (fifteenNumber.length() == 15) {
                fifteenNumber = fifteenNumber.substring(0, 6) + "19" + fifteenNumber.substring(6, 15);

                int[] temp1 = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
                char[] temp2 = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
                char[] temp3 = fifteenNumber.toCharArray();
                int temp4 = 0;
                int temp5 = 0;
                int temp6;
                for (int i = 0; i < 17; i++) {
                    temp6 = Integer.parseInt("" + temp3[i]);
                    temp4 = temp6 * temp1[i];
                    temp5 += temp4;
                }
                temp5 = temp5 % 11;

                fifteenNumber += temp2[temp5];
            }
        } catch (Exception e) {

        }
        return fifteenNumber;
    }
}
